#!/bin/sh
logfile=/data/bcp/011.521.000.345/trans.log
status=/data/bcp/011.521.000.345/cachefile.doing
if [ -f "$status" ]
then
echo `date '+%Y-%m-%d %T'` "other trans program is running" >> $logfile
exit 0
fi 
bcpdir=/data/bcp/011.521.000.345/003
cachingfile=/data/bcp/011.521.000.345/cachefile.doing
cachefile=/data/bcp/011.521.000.345/cachefile
mv $cachefile $cachingfile

read lastdirname < $cachingfile
counter=0
if [ -d "$bcpdir" ] 
then
        cd $bcpdir
        filelist=`ls $bcpdir`
        for filename in $filelist
          do
            if [ $filename -gt $lastdirname ]
            then
                echo `date '+%Y-%m-%d %T'` "trans file " $filename >> $logfile
                scp -i /data/bcp/011.521.000.345/id_rsa_218.241.190.38 -r $filename  root@218.241.190.38:/data6/
                echo $filename > $cachingfile
                let counter++
           fi 
          done
        mv $cachingfile $cachefile
        if [ $counter -eq 0 ]
        then
          echo `date '+%Y-%m-%d %T'` "none file need trans" >> $logfile
        else
          echo `date '+%Y-%m-%d %T'` $counter "file was trans" >> $logfile
          let counter=0
        fi

else
        echo "the dir " $bcpdir "not exist !!!"
fi
